//
//  CapitalListTableViewCell.swift
//  jiaoyi
//
//  Created by wjk on 2018/8/8.
//  Copyright © 2018年 wjk. All rights reserved.
//

import UIKit
import SwiftyJSON

class CapitalListTableViewCell: UITableViewCell {
    
    @IBOutlet weak var labelLiuNo: UILabel!
    @IBOutlet weak var directionLabel: UILabel!
    
    @IBOutlet weak var labelDai: UILabel!
    @IBOutlet weak var labelYue: UILabel!
    @IBOutlet weak var contractIdLabel: UILabel!
    
    @IBOutlet weak var labelBaoz: UILabel!
    @IBOutlet weak var priceLabel: UILabel!
    
    @IBOutlet weak var dateLabel: UILabel!
    func directionAbstract(_ direction:Int) -> String{
       
        switch direction {
        case 1:
            return "收入"
        case 2:
            return "支出"
        default:
            return "内转"
        }
    }
    var model: JSON!{
        didSet{
            labelLiuNo.text = model["operation_no"].stringValue
            
            directionLabel.text = "【"+directionAbstract(model["direction"].intValue)+"】"
            directionLabel.text?.append(model["abstract"].stringValue)
            
            contractIdLabel.text = model["contract_no"].stringValue
            
            let formater = NumberFormatter()
            
            formater.numberStyle = .decimal
            formater.minimumFractionDigits = 2
            formater.maximumFractionDigits = 2
            
//            let json = jsonFormater(data: ["effect":model.effect!])
            
            let st = formater.string(from: NSNumber(value:model["effect"].floatValue / 100.0))!
            
            priceLabel.attributedText = StyledTextBuilder(text: "")
                .save()
                .add(text: st, traits: [.traitBold], attributes: [NSAttributedStringKey.foregroundColor:UIColor.red, NSAttributedStringKey.font:UIFont.systemFont(ofSize: 16)])
                .restore()
                .add(text: " 元", traits: [.traitBold], attributes: [NSAttributedStringKey.foregroundColor:UIColor.black, NSAttributedStringKey.font:UIFont.systemFont(ofSize: 14)])
                .restore()
                .build()
                .render(contentSizeCategory: .large)
            
            
//            priceLabel.text = "\(st) 元"
            
            dateLabel.text = model["operation_time"].stringValue
            
            labelYue.text = "\(formater.string(from: NSNumber(value:model["available_fund"].doubleValue / 100.0))!)"
            
            labelBaoz.text = "\(formater.string(from: NSNumber(value:(model["frozen_perform_deposit"].doubleValue + model["frozen_trade_deposit"].doubleValue) / 100.0))!)"
            
            labelDai.text = "\(formater.string(from: NSNumber(value:model["frozen_payment"].doubleValue / 100.0))!)"
            
            
//            if let ab = model.abstract{
//                directionLabel.text = "【"+model.directionAbstract()+"】" +  model.abstract ?? ""
//            }
            
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
